package com.ruoyi.system.service.impl;

import java.math.BigDecimal;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.vo.CustomerTransactionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.CustomerTransactionMapper;
import com.ruoyi.system.domain.CustomerTransaction;
import com.ruoyi.system.service.ICustomerTransactionService;

/**
 * 客户账户流水Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-12-16
 */
@Service
public class CustomerTransactionServiceImpl implements ICustomerTransactionService 
{
    @Autowired
    private CustomerTransactionMapper customerTransactionMapper;

    /**
     * 查询客户账户流水
     * 
     * @param id 客户账户流水主键
     * @return 客户账户流水
     */
    @Override
    public CustomerTransaction selectCustomerTransactionById(Long id)
    {
        return customerTransactionMapper.selectCustomerTransactionById(id);
    }

    @Override
    public CustomerTransaction CustomerTransactionById(Long id) {
        return customerTransactionMapper.CustomerTransactionById(id);
    }

    /**
     * 查询客户账户流水列表
     * 
     * @param customerTransaction 客户账户流水
     * @return 客户账户流水
     */
    @Override
    public List<CustomerTransactionVo> selectCustomerTransactionList(CustomerTransactionVo customerTransaction)
    {
        return customerTransactionMapper.selectCustomerTransactionList(customerTransaction);
    }

    /**
     * 新增客户账户流水
     * 
     * @param customerTransaction 客户账户流水
     * @return 结果
     */
    @Override
    public int insertCustomerTransaction(CustomerTransaction customerTransaction)
    {
        customerTransaction.setCreateTime(DateUtils.getNowDate());
        return customerTransactionMapper.insertCustomerTransaction(customerTransaction);
    }

    /**
     * 修改客户账户流水
     * 
     * @param customerTransaction 客户账户流水
     * @return 结果
     */
    @Override
    public int updateCustomerTransaction(CustomerTransaction customerTransaction)
    {
        customerTransaction.setUpdateTime(DateUtils.getNowDate());
        return customerTransactionMapper.updateCustomerTransaction(customerTransaction);
    }

    /**
     * 批量删除客户账户流水
     * 
     * @param ids 需要删除的客户账户流水主键
     * @return 结果
     */
    @Override
    public int deleteCustomerTransactionByIds(Long[] ids)
    {
        return customerTransactionMapper.deleteCustomerTransactionByIds(ids);
    }

    /**
     * 删除客户账户流水信息
     * 
     * @param id 客户账户流水主键
     * @return 结果
     */
    @Override
    public int deleteCustomerTransactionById(Long id)
    {
        return customerTransactionMapper.deleteCustomerTransactionById(id);
    }






    /**
     * 新增客户账户流水
     *
     * @param customerTransaction 客户账户流水
     * @return 结果
     */
//    @Override
//    public int insertCustomerTransaction(CustomerTransaction customerTransaction)
//    {
//        //根据当前的客户ID找出客户最近的一次账户流水记录
//        CustomerTransaction transaction = customerTransactionMapper.selectCustomerTransactionByCustomerID(customerTransaction.getCustomerId());
//        if(null==transaction){
//        //将本次的交易金额付给本期余额
//            customerTransaction.setCurrentBalance(customerTransaction.getTransactionAmount());
//        }else{
//        //将查询出来的上一批交易的当前余额赋给本次流水的上期余额字段
//            customerTransaction.setPreviousBalance(transaction.getCurrentBalance());
//        //本次流水的当前余额=上次流水的当前余额+本次交易金额
//            BigDecimal money = customerTransaction.getTransactionAmount().add(transaction.getCurrentBalance());
//            customerTransaction.setCurrentBalance(money);
//        }
//        String transactionCodeId="Ts_"+System.currentTimeMillis();
//        customerTransaction.setTransactionCode(transactionCodeId);
//        customerTransaction.setCreateTime(DateUtils.getNowDate());
//        customerTransaction.setUpdateTime(DateUtils.getNowDate());
//        return customerTransactionMapper.insertCustomerTransaction(customerTransaction);
//    }








}
